<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.regNo" placeholder="注册证号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <dictionary-select dictType="reg_type" placeholder="证件类型" :dictionaryName.sync="dataForm.regTypeName" :dictionaryCode.sync="dataForm.regTypeCode"></dictionary-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.facName" placeholder="生产企业" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.regGoodsName" placeholder="注册产品名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <!--<el-input v-model="dataForm.expDate" placeholder="即将过期" clearable></el-input>-->
        <el-select v-model="dataForm.expDate" placeholder="请选择过期时间">
          <el-option label="已过期" value="0"></el-option>
          <el-option label="近一个月" value="30"></el-option>
          <el-option label="近三个月" value="90"></el-option>
          <el-option label="近六个月" value="180"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.status" placeholder="状态" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="clearDataList()">重置</el-button>
        <el-button v-if="isAuth('basedata:goodsreg:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <!--<el-table-column
        prop="regCode"
        header-align="center"
        align="center"
        label="注册证编码">
      </el-table-column>-->
      <!--<el-table-column
        prop="regNo"
        header-align="center"
        align="center"
        label="注册证号">
      </el-table-column>-->
      <!--<el-table-column
        prop="regTypeCode"
        header-align="center"
        align="center"
        label="证件类型代码">
      </el-table-column>-->
      <el-table-column
        prop="regTypeName"
        header-align="center"
        align="center"
        label="证件类型名称">
      </el-table-column>
      <!--<el-table-column
        prop="facCode"
        header-align="center"
        align="center"
        v-if="isShowfacCode"
        label="生产企业编码">
      </el-table-column>-->
      <el-table-column
        prop="facName"
        header-align="center"
        align="center"
        label="生产企业名称">
      </el-table-column>
      <!--<el-table-column
        prop="facRegAddr"
        header-align="center"
        align="center"
        label="企业注册地址">
      </el-table-column>
      <el-table-column
        prop="facProduceAddr"
        header-align="center"
        align="center"
        label="企业生产地址">
      </el-table-column>-->
      <el-table-column
        prop="regGoodsName"
        header-align="center"
        align="center"
        label="注册产品名称">
      </el-table-column>
      <!--<el-table-column
        prop="goodsModel"
        header-align="center"
        align="center"
        label="型号规格">
      </el-table-column>
      <el-table-column
        prop="productStandards"
        header-align="center"
        align="center"
        label="产品标准">
      </el-table-column>
      <el-table-column
        prop="productPerformance"
        header-align="center"
        align="center"
        label="产品性能结构及组成">
      </el-table-column>
      <el-table-column
        prop="productIndications"
        header-align="center"
        align="center"
        label="产品适用范围">
      </el-table-column>
      <el-table-column
        prop="productContraindications"
        header-align="center"
        align="center"
        label="产品禁忌症">
      </el-table-column>
      <el-table-column
        prop="productAgent"
        header-align="center"
        align="center"
        label="代理人">
      </el-table-column>
      <el-table-column
        prop="productServiceAgent"
        header-align="center"
        align="center"
        label="售后服务机构">
      </el-table-column>
      <el-table-column
        prop="regScope"
        header-align="center"
        align="center"
        label="国家标准分类">
      </el-table-column>
      <el-table-column
        prop="operateType"
        header-align="center"
        align="center"
        label="经营方式">
      </el-table-column>
      <el-table-column
        prop="legalName"
        header-align="center"
        align="center"
        label="法人">
      </el-table-column>
      <el-table-column
        prop="principalName"
        header-align="center"
        align="center"
        label="负责人">
      </el-table-column>
      <el-table-column
        prop="perAddr"
        header-align="center"
        align="center"
        label="住所">
      </el-table-column>
      <el-table-column
        prop="businessAddr"
        header-align="center"
        align="center"
        label="经营场所">
      </el-table-column>
      <el-table-column
        prop="warehouseAddr"
        header-align="center"
        align="center"
        label="库房地址">
      </el-table-column>-->
      <el-table-column
        prop="beginDate"
        header-align="center"
        align="center"
        label="有效期开始日期">
      </el-table-column>
      <el-table-column
        prop="endDate"
        header-align="center"
        align="center"
        label="有效期结束日期">
      </el-table-column>
      <!--<el-table-column
        prop="flag"
        header-align="center"
        align="center"
        label="是否长期1是长期">
      </el-table-column>
      <el-table-column
        prop="regOrg"
        header-align="center"
        align="center"
        label="发证部门">
      </el-table-column>
      <el-table-column
        prop="regDate"
        header-align="center"
        align="center"
        label="发证日期">
      </el-table-column>-->
      <el-table-column
        prop="statusName"
        header-align="center"
        align="center"
        label="状态">
      </el-table-column>
      <!--<el-table-column
        prop="createUserId"
        header-align="center"
        align="center"
        label="创建者id">
      </el-table-column>
      <el-table-column
        prop="createBy"
        header-align="center"
        align="center"
        label="创建者名称">
      </el-table-column>-->
      <el-table-column
        prop="createDate"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
     <!-- <el-table-column
        prop="updateUserId"
        header-align="center"
        align="center"
        label="更新者id">
      </el-table-column>
      <el-table-column
        prop="updateBy"
        header-align="center"
        align="center"
        label="更新者名称">
      </el-table-column>
      <el-table-column
        prop="updateDate"
        header-align="center"
        align="center"
        label="跟新时间">
      </el-table-column>
      <el-table-column
        prop="remarks"
        header-align="center"
        align="center"
        label="备注信息">
      </el-table-column>-->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.regCode)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './goodsreg-add-or-update'
  import DictionarySelect from '@/components/common/dictionary-select'
  export default {
    data () {
      return {
        dataForm: {
          regNo: '',
          regTypeName: '',
          regTypeCode: '',
          facName: '',
          regGoodsName: '',
          expDate: '',
          status: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      DictionarySelect,
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl(this.$API.BASE_INFO.GOODSREG.LIST),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'regNo': this.dataForm.regNo,
            'regTypeCode': this.dataForm.regTypeCode,
            'facName': this.dataForm.facName,
            'regGoodsName': this.dataForm.regGoodsName,
            'expDate': this.dataForm.expDate,
            'status': this.dataForm.status
          })
        }).then((data) => {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
          this.dataListLoading = false
        })
      },
      // 清空数据列表
      clearDataList () {
        for (let i in this.dataForm) {
          this.dataForm[i] = ''
        }
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.regCode
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(this.$API.BASE_INFO.GOODSREG.DELETE),
            method: 'delete',
            data: this.$http.adornData(ids, false)
          }).then((data) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
